﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LocalSettings
{
	public class GYMSettingsStorage : BaseSettingsStorage
	{
		private static String BLA_KEY = "VISIBILITY_SETTINGS_BLA_KEY";
		public static List<Guid> LoadOrder()
		{
			return LoadChain<Guid>(BLA_KEY, s => 
			{
				return Guid.Parse(s);
			});
		}

		public static void SaveOrder(IEnumerable<Guid> items)
		{
			SaveChain<Guid>(BLA_KEY, items);
		}

		public static void Reset()
		{
			SaveOrder(null);
		}

		public static String LastErrorStackTrace
		{
			get { return BaseSettingsStorage.GetPropertyResult<String>("error", ""); }
			set
			{
				BaseSettingsStorage.SetPropertyResult("error", value);
			}
		}

		//public static String GetDebug()
		//{
		//	return BaseSettingsStorage.GetPropertyResult<String>("debug", "");
		//}

		//public static void SetDebug(String str)
		//{
		//	BaseSettingsStorage.SetPropertyResult("debug", String.Format("{0} | {1}", GetDebug(), str));
		//}

		//public static void ResetDebug()
		//{
		//	BaseSettingsStorage.SetPropertyResult("debug", "");
		//}

        public static Int32 IncRateAttemptCount()
        {
            var newVal = BaseSettingsStorage.GetPropertyResult<Int32>("GYM_LaunchCount", 0) + 1;
            BaseSettingsStorage.SetPropertyResult("GYM_LaunchCount", newVal);
            return newVal;
        }


        private static Int32 DefaultLaunchCountForRate = 40;
        public static Int32 LaunchCountForRate 
        {
            get { return BaseSettingsStorage.GetPropertyResult<Int32>("GYM_LaunchCountForRate", DefaultLaunchCountForRate); }
            set
            {
                BaseSettingsStorage.SetPropertyResult("GYM_LaunchCountForRate", value);
            }
        }

        public static void IncLaunchCountForRate(Int32? offset = null)
        {
            LaunchCountForRate += offset.HasValue ? offset.Value : DefaultLaunchCountForRate;
        }

        public static Boolean RateDialogIsShown
        {
            get { return BaseSettingsStorage.GetPropertyResult<Boolean>("GYM_RateDialogIsShown", false); }
            set
            {
                BaseSettingsStorage.SetPropertyResult("GYM_RateDialogIsShown", value);
            }
        }
    }
}
